package com.lg.erp.controller.chenkang;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lg.erp.entity.JsonResult;
import com.lg.erp.entity.chenkang.TWare;
import com.lg.erp.service.chenkang.IWareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.UUID;

@RestController
public class WareController {

    @Autowired
    private IWareService wareService;

    /*根据货位来查询空置货位*/
    @RequestMapping("/ware/cargo")
    public JsonResult selectWareByCargoProductNo(){
        Integer integer = wareService.selectWareByCargoProductNo();
        return new JsonResult(1,"ok",integer);
    }

    //分页(模糊查询)
//    @RequestMapping("/ware/{current}")
    @RequestMapping("/ware")
    public JsonResult pageWare(@RequestParam(value = "current",required = false,defaultValue = "1")
                                           Integer current,String name,String dateTime){
        Page<TWare> page=new Page<>(current,10);
        IPage<TWare> pages=wareService.pageWare(page,name,dateTime);

        System.out.println("pages的值"+pages);
        return new JsonResult(1,"ok",pages);

    }


    //增加
    @PostMapping("/ware")
    public JsonResult saveWare(@RequestBody TWare ware){
        ware.setId(UUID.randomUUID().toString().substring(0,7));
        ware.setDeteTime(new Timestamp(System.currentTimeMillis()));
        wareService.save(ware);
        return new JsonResult(1,"创建成功",ware);
    }
    //修改
    @PutMapping("/ware")
    public JsonResult updateWare(@RequestBody TWare ware){
        wareService.updateById(ware);
        return new JsonResult(1,"更新成功",ware);

    }
    @RequestMapping(value = "/ware/{id}",method = RequestMethod.DELETE)
    public JsonResult removeWare(@PathVariable("id") String id){
        wareService.removeById(id);
        return new JsonResult(1,"删除成功",id);
    }

}
